{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <div class="layui-form" lay-filter="announcement-form" id="announcement-form" style="padding: 20px 30px 0 0;">
            <div class="layui-form-item">
                <label class="layui-form-label">公告标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" placeholder="请输入公告标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">公告内容</label>
                <div class="layui-input-block">
                    <!-- 使用script标签，用于UEditor初始化 -->
                    <script id="editor" name="content" type="text/plain" style="width:100%;height:400px;"></script>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/static/Ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/static/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    // 初始化UEditor富文本编辑器
    var ue = UE.getEditor('editor', {
        toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
            'print', 'preview', 'searchreplace', 'drafts', 'help'
        ]],
        autoHeightEnabled: true,
        autoFloatEnabled: true,
        initialFrameHeight: 400
    });
    layui.use(function(){
        var $ = layui.$;
        var form = layui.form;
        

        
        // 表单提交
        layui.form.on('submit(demo1)', function(data){
            var field = data.field;
            
            // 获取UEditor内容
            field.content = ue.getContent();
            
            // 表单验证
            if(!field.title){
                layer.msg('标题不能为空', {icon: 5});
                return false;
            }
            if(!field.content){
                layer.msg('内容不能为空', {icon: 5});
                return false;
            }
            $.ajax({
                type: "POST",
                url: "{:url('add')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('提交成功');
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false; // 阻止默认 form 跳转
        });
    });
</script>
</body>
</html>